#define _CRT_SECURE_NO_WARNINGS 1
#include"queue.h"
queue* qu_create() {
	queue* newque;
	newque = malloc(sizeof(*newque));
	if (!newque)
		return NULL;
	newque->head = 0;
	newque->tail = 0;
	return newque;
}

int qu_isempty(queue* q) {
	
	return (q->tail == q->head);
}

void qu_destroy(queue*q) {
	free(q);
	q = NULL;
}

void qu_travel(queue*q) {
	int i;
	if (q->tail == q->head)
		return;
	i = (q->head + 1) % MAXSIZE;
	while (i != q->tail)
	{
		printf("%d  ", q->data[i]);
		i =( i + 1)%MAXSIZE;
	}
	printf("%d\n", q->data[i]);
}

int qu_enqueue(queue*q,const datatype* data) {
	if ((q->tail+1) % MAXSIZE == q->head)
		return -1;
	q->tail = (q->tail + 1) % MAXSIZE;
	q->data[q->tail] = *data;
	return 0;
}

int qu_dequeue(queue*q, datatype* data) {
	if (qu_isempty(q))
		return -1;	
	q->head = (q->head + 1) % MAXSIZE;
	*data = q->data[q->head];
	return 0;

}

void qu_clear(queue* q) {
	q->tail = q->head;
}
